package com.google.code.b0rx0r.program;

import java.io.Serializable;
import java.util.Collections;
import java.util.Set;

import org.tritonus.share.sampled.FloatSampleBuffer;

import com.google.code.b0rx0r.advancedSamplerEngine.ChannelOutputMap;

public class Slice extends AbstractTriggerable implements Serializable, SampleDataContainer, Sequencable, OffsetSampleDataContainer {
	private static final long serialVersionUID = "Slice 1.0.1".hashCode(); //$NON-NLS-1$
	
	private Set<OffsetSampleDataContainer> asSet = Collections.<OffsetSampleDataContainer>singleton(this);

	private Sample sample;
	private SnapPoint start;
	private SnapPoint end;
	private ChannelOutputMap outputMap = new ChannelOutputMap();
	
	public Slice(Sample sample, SnapPoint start, SnapPoint end) {
		this.sample = sample;
		this.start = start;
		this.end = end;
		
		outputMap.copyFrom(sample.getOutputMap());
	}


	public Sample getSample() {
		return sample;
	}


	public SnapPoint getStart() {
		return start;
	}


	public void setStart(SnapPoint start) {
		this.start = start;
	}


	public SnapPoint getEnd() {
		return end;
	}


	public void setEnd(SnapPoint end) {
		this.end = end;
	}



	@Override
	public int getStartOffset() {
		return start.getOffset();
	}
	
	@Override
	public int getEndOffset() {
		return end.getOffset();
	}


	@Override
	public FloatSampleBuffer getFloatSampleBuffer() {
		return sample.getFloatSampleBuffer();
	}


	@Override
	public int getLength() {
		return end.getOffset() - start.getOffset();
	}


	@Override
	public Iterable<SnapPoint> getRelativeSnapPoints() {
		return new SnappointView(this, sample.getSnapPoints().iterator(), start.getOffset(), end.getOffset());
	}


	@Override
	public void fireSnapPointMoved(SnapPoint snapPoint) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public Set<OffsetSampleDataContainer> getSampleData() {
		return asSet;
	}


	@Override
	public int getOffset() {
		return 0;
	}


	@Override
	public SampleDataContainer getSampleDataContainer() {
		return this;
	}


	@Override
	public ChannelOutputMap getOutputMap() {
		return outputMap;
	}


	@Override
	public float getPlaybackSpeed() {
		return sample.getPlaybackSpeed();
	}

	
	
	
	

}
